package com.all.utils;

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.InputStream;
import java.io.InputStreamReader;
import android.content.Context;
import android.util.Log;

public class FileUtils {
	
	
	/**
	 * 读取文本文件
	 * 
	 * @param context
	 * @param fileName
	 * @return
	 * @throws FileNotFoundException 
	 */
	public static String read(Context context, String fileName)  {
		InputStream inputStream;
		try {
			inputStream = context.openFileInput(fileName);
			return readInputStream(inputStream);
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			Log.i("FileTest", e.getMessage());
		}
		return "";
		

		
	}
	public static String readInputStream(InputStream input) 
	{     
	    String fileContent = "";  
	    InputStreamReader read;
		try {
			read = new InputStreamReader(input, "GBK");
			BufferedReader reader = new BufferedReader(read);
			String line;
			while ((line = reader.readLine()) != null) {
				fileContent += line;
			}
			read.close();   
			return fileContent;   
		} catch (Exception e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
		return fileContent;
	   
	}
}
